Hey there.
We're going to start wrapping up our project by bringing everything together.
Specifically here, we need to fill out our SCP 294 handler server script and require the drink class
that exists for the server.
That way we can get everything set up and we can test out our SCP.
So let's go ahead and go into the server script service and open up our SCP 294 handler.
Inside of here we're only going to need two services.
One is going to be replicated storage.
And then the other service we'll need is the collection service.
That way we can collect all of the ships in our game and, you know, find them using that tag we created
for it.
So inside of our variables section I'm going to create a reference to the communications event.
So we can do replicated storage.
SCP 294 assets communication.
And then we're going to require the drink class.
So we'll require inside of replicated storage SCP 294 assets.
And we can get the drink class for the server.
That way we can execute all of the code inside of this module script and get everything set up and ready
to go.
Now, the other thing I want to do is I want to create a table.
I'm going to call it Scp's, and we're going to use the collection service to get all of the ships that
are tagged with the specific tag we created in the beginning of the lecture, which was SCP 294.
So actually we can create a constant.
For simplicity's sake, I'll just call it SCP tag, and we'll set it to a string of SCP 294.
And this was the tag we set for all of the SCP 294 in our game.
So this is going to collect all of the instances in our game that has this tag, specifically our vending
machine.
And then once we get all of those steps, what we could do is we could loop through every single one
of those and set up a function to be attached to our proximity prompt that is inside of our steps.
And then when that proximity prompt gets activated by a player, we can tell them to open up the guy
on their screen so we can create a function.
We'll call it on prompt triggered.
And I don't know how many steps are going to be in the game.
So it's better to have a function that each of the steps can refer to, rather than creating a new lambda
function for every single step.
And this function will just take a player which gets passed by the triggered event.
So we can loop through every single step in the table steps.
And what we could do is we could do SCP and we're going to find First child, which is a proximity prompt.
And then there's a second property we can pass to this function, which is called recursive.
And we're going to pass true.
And what this does is that this function is now going to search through all the descendants of our SCP.
So instead of looking through the direct descendants of our SCP, which would be just this attachment,
the function is now going to look through all of the descendants, so it'll look an attachment, and
then look to see if there's a proximity prompt, an attachment which there is.
So we're going to grab that proximity prompt.
And once we do that we can access our triggered event and connect the on prompt triggered function to
this event.
And again we're referencing the function to this not calling it.
Now what do we want to do when the prompt gets triggered?
Well, we can use the comms event and fire to this particular player and tell them to enable the GUI
like we defined in our SCP 294 GUI handler.
So right here we're listening to the comms event, and whenever we get told to enable the GUI, we're
going to open the GUI on our screen.
And that's all we need to do for our SCP 294 handler.
The main purpose is just to require our drink class, and set up all the SCP so we can go ahead and
use them.
So that now means we should be able to test out our SCP so we can go ahead and do test and play right
here.
And let's see if we can get a cup of air.
So if we go up to our machine and trigger it.
We get called to open guy on our screen.
Very cool.
And we should be able to click these buttons and it'll play the click sound for us and display that
character on the display.
So if I hit a, we get the sound and A is displayed.
We could do I and then R, and then we can hit the enter key to get a cup of air.
As you can see it's now dispensing.
And we get our cup of air.
There's nothing inside of it and we shouldn't be able to drink it either.
So when I click it, there we go.
It gets destroyed and it tells us there is nothing in the cup.
And then this message should fade out.
Perfect.
So our sap is all now good and set up.
That means we can go ahead and create some more drinks.
So for example, let's go ahead and go to our pre-made drinks module script and let's create a new drink.
For example let's create a drink.
We could do something like we'll just call it juice.
And all the strings we can accept for this particular drink can be something like apple juice.
We can just do juice.
We could do maybe grape juice, whatever the case may be for this particular drink.
And then down here we can create a new section for this particular drink.
Remember to have the exact same key of juice.
And then for the consumed message, we could say something like it tastes like a sweet juice.
We'll change the dispense sound to be the regular dispense.
Sound.
So dispense.
And then this cup isn't going to be empty.
So we're just going to set this to false.
And we can give it a name like, uh, juice.
And then we'll set the transparency to something maybe like 0.5.
And then we can select an interesting color.
Actually I'll change this to from RGB.
And we can select a color for our juice.
Maybe give it like a slight kind of yellowish tannish hue, maybe something like that.
And now that we have this new drink in here.
Oh, don't forget to put a comma here.
For every new key value pair you define in our table, that means we should be able to go back and play
our game and dispense this new drink.
All right, so we interact, we open the GUI.
Let's go ahead and get a cup of juice.
Perfect.
Here, we got our cup of juice.
Um, it's not really looking like juice, but it's fine.
We can change that later.
And.
Perfect.
It tastes like a sweet juice.
Alrighty.
So now let's get to the fun part and create some functionality for some specific drinks.
So for example, in the beginning I showed you that we created a cup of pain and got punched in the
face.
So let's go ahead and create that drink.
So inside of pre-made drinks we can define a new drink in here I'll just call it pain.
And someone could input anything like pain.
I don't know, suffering.
Injury, hurt, whatever they could type in whatever they like, and we can give them a cup of pain.
So we'll define another new key value pair here.
So for pain.
We could say something like, you feel like you just got punched by Mike Tyson for the dispense sound.
We can set something interesting like dispense sound.
Angry is empty, will be set to false.
And then we can change the name to pain.
And then we could go ahead and change the color to maybe set it to, like, a deep red.
And we can change the material, maybe to something like neon.
And then we can set the transparency to be completely opaque.
And actually I'll change this red color to be not as intense.
Something like that.
And then we can go to our pre-made drinks function module script.
So inside of replicated storage we'll open that up.
Pre-made drink functions, and we could go ahead and define a function for this particular drink of
pain.
So I'm going to get rid of this and define it for our pain drink.
And I'm going to want to refer to replicated storage inside of this module script.
And that's because I want to be able to access the comms event.
So replicated storage, get our assets communication.
And that way I can tell the server to do some server side effects, which specifically for this drink
we want to remove some health from the player.
And then we could also use the tween service as well to tween some things on the client screen.
So we'll get the tween service.
So when the player drinks the pain drink.
What do I want to happen?
Well, first I want to be able to reference the player's character and you'll see why in a moment.
So I'll just call it current char and it's going to be equal to the drink object dot owner.
And we're going to get their character.
And then I'm going to put an if statement here to make sure that this script is running on the client.
So at the top here what I could do.
Is I'll create a boolean, I'll call it is client equal to.
And that means we're going to have to access the run service.
So run service.
And then we can use the function is client.
That way we can differentiate whether or not this function is being called on the server or on the client.
So if is client then we'll execute client functionality in here.
And at the end just return true.
Otherwise any other functionality that isn't for the client will be executed down here, which will
be the server.
And we can just do return true as well.
It doesn't really matter.
So on the client, um, what I want to do is I want to create two new instances.
One is going to be something called a color correction effect.
So color correction effect.
And let me actually show you this as an example.
So if I were to put a color correction effect in my camera I can tweak some of these things and tint
the screen color to be something different.
So as you can see I can tint the color of the screen to be whatever.
I can change the brightness.
Uh, that's a little bright, but as you can see, I can tweak the brightness.
I can tweak the contrast so I can make it.
Oops.
Do something like that, change the contrast or make it higher.
And of course, I can also change the saturation to make the colors more saturated or more washed out.
Pretty neat.
So we're going to use this color correction effect to make it look like we got punched.
So we'll get a new color correction effect.
And then I'm also going to get a blur as well.
So a new blur effect.
And again this instance just blurs the screen.
So that's a pretty simple one.
And then what I could do with these is I could tween them or fade them to appear on the screen.
So for our color, what I could do is I'll create a tween, I'll call it tween color and use the tween
service to create a new tween on our new color instance.
And we'll make it last.
Something like maybe 0.3 seconds.
And what do I want to tween?
Well, I want to tween the tint color to be equal to a new color.
So color three from RGB.
And I want to tween the screen to be completely black like like kind of like we lost consciousness.
So actually if I put this color correction effect back in here, and if I tween it to be all the way
completely black, as you see our screen turns completely dark.
So I want to apply that effect to make it look like we got punched and knocked out.
And then we will wake back up from our knockout.
So we'll tween it to be completely black.
And then for the blur I'm going to bore the screen as well.
So I'll call this Tween Blur equal to the tween service we'll create on our.
For instance this one can be a little bit longer.
Maybe we'll tween it to be 0.6 seconds long.
And the blur instance has a property called size.
And we'll set it equal to something like 12.
So it'll be a little bit bored on our screen.
And of course you can define this as a string or you can literally just type it out as well.
It doesn't really matter.
Now using the current character that we just stored inside of this variable, I want to listen for when
the player dies.
So we get their humanoid and listen to the died event, and we're going to connect a Lambda function
to it.
And that's because when the player dies, I want to remove these instances from their camera, because
what we're going to do is we're going to set the parent of these onto the player's current camera.
So what we could do is if the player dies, we want to check if we still have the color and blur.
So if we have not destroyed them yet by the end of the script, then we want to make sure to destroy
them when the player dies.
And then we want to make sure to set them to nil as well.
So this function is going to be extremely important for removing effects off of our screen when the
player dies.
Otherwise, once we do that, um, by default when we create a new board instance, it's going to have,
I believe, a default of 24.
So we want to make sure to set the blur dot size equal to zero.
And then we can set the color dot parent equal to the workspace and get the current camera of the player,
and then do the same thing for the blur.
And then I also want to reference actually the sound service game.
The sound service, because in there there is an audio file we can use for being punched in the face.
So if we go to the sound service I have a punched audio file here.
So we'll play that when they consume the drink so we can do sound service.
Get the SCP 294 sounds folder, access our punch sound and play that.
And once we play that sound, we can tween the blur onto our screen.
As well as the color.
And let me play this again.
There is a slight delay for when this sound plays the punch noise, so we can actually maybe yield for
like 0.1 seconds before we actually fade the screen to be black.
And I'm going to wait for our tween color.
To finish, so we're going to wait for that to finish.
And once we wait, we'll need to create a new tween for the color on our screen.
So we'll override tween color to a new tween so we can use the tween service to create a new tween on
our color instance.
And this tween will last something like 0.1 seconds.
And we want to tween the tint color to be a slightly red.
So from RGB we can set it to be of a slightly red color.
So if we go on here, we can make the color.
Maybe something around there that would be good.
So our screen is slightly red and then we can play this tween again.
And then once we play this tween, um, we can tell the server to remove health off of us so we can
use the comms event, and we can fire to the server to execute some functionality for this particular
drink.
So if you remember in our drink class for the server in our comms event, we can have an action of drink
effects.
And we pass the ID of this drink object.
And if the player owns that drink object and the effects debounce hasn't been set to true yet, then
it's going to execute all the functionality for the server so we can fire the server to execute some
particular drink effects, and we can pass the drink object.id.
And actually, one more thing I'll do is I'll override our blur tween as well.
So we'll set it to a new tween.
And I'll make this tween actually last something like perhaps 10s long.
So we'll set the size equal to zero.
So our blur will fade out of our screen over time.
And we can play this tween as well.
And then we're going to wait for our tween blur to finish.
So tween Blur dot completed.
We're going to wait for that, which will be about 10s.
And then once those 10s are up, we're going to ensure that we still have this color and blur on our
screen, because in those 10s we've waited, the player could have reset and the color correction effect
and the blur effect could have already been destroyed.
So we need to make sure that color and blur are not nil.
So if color and blur.
So if they still exist, then we need to destroy them.
We can do.
Borer.
Destroy.
And then set bore equal to nil.
That way it won't be able to destroy it here when our player dies.
And then we should also fade the color back out from our color correction effect.
So actually, one last time, what we could do is we could override the tween color again to a new tween.
So we get the tween service created on our color.
And we can make this last.
I don't know maybe about 10s as well.
And we'll set the tent color.
Just to be equal to white.
So color three dot new or dot from RGB.
We'll just set it to be completely white because that's the default color.
And we can play that again as well.
And then once those are finally up, then we'll just destroy the blur, set it to nil, and we could
do the same thing for the color, so color will destroy it.
And we'll make sure to set it to nil as well.
Now, of course, you could also store the connection for our humanoid in a variable.
You can just call it connection.
And instead of needing to set border and color to nil, you could also just destroy the connection as
well.
So we'll actually do both here just in case.
So we'll get this connection and we'll disconnect it.
So now what I need to do is I need to fill out the server functionality for this particular drink.
Because when we tell the server to execute the effects for this drink, um, what do I want to do?
Well, I just want to remove some health from this particular player so we could get their current character
that we stored originally here in this variable, and we can set their humanoid's health to be less,
or we can use a function on our humanoid called take damage.
And what we could do is maybe we could just reduce their health by half so we can access their humanoid,
get their health, and divide it by two.
That way they lose half of their health.
So that's all the server is going to do here.
So this is our server functionality.
And this is the client functionality.
So now that we have this applied, let me go ahead and delete these other effects that I've already
put on our camera.
And we can go ahead and play test the game.
And let's go ahead and get a cup of pain.
So let's get a cup of pain.
We get the, uh, very angry dispense sound.
And when we drink our cup, we should have our screen fade to black.
Our screen should be blurry, slightly red, and we should lose half of our health.
So there we go.
We've imitated a punch on our screen.
Our screen went black and we lost half of our health thanks to the replication done by the server.
So let's go ahead and actually demonstrate that again.
So we get our cup of Penn.
We drink it.
Screen fades to black, our screens all blurry, and then it slowly fades out.
Now, I did make a little error in my logic here because our screen didn't turn red.
And that's because I play the tween, and because this play function doesn't yield, it immediately
set the color to white.
So what I do is for our tween color.
Um, well, wait for this event to finish.
So twin color dot completed.
Wait.
So that way our screen is red for a little bit, and then we can fade it out towards white.
So we can actually make this effect last longer as well.
So instead of 10s we can make it last maybe 20s.
That way we could see if our screen stays red for a little bit longer.
So we go and drink.
So we get our cup of pain.
We drink it.
There we go.
Now our screen is red and it stays red for quite a while.
Our screen's kind of blurry because we're recovering after we drank a cup of pain.
As you can see, we can't drink our cup anymore.
But once our effects end.
Our cup should get deleted.
So any second now, our cup, there we go.
So our cup gets deleted because when we execute our drink functionality here, the threat of execution
is jumping into our handler function and executing all the client stuff.
And then once that's finally all over, then it'll go and destroy the drink and tell the server to destroy
the drink as well.
Alrighty, so we're almost finished with our SCP project, and the next lecture, we're going to be
wrapping everything up and fixing a few things, so I'll go ahead and see you there.